const Service = require('egg').Service
const jwt = require('jsonwebtoken')
const fs = require('fs')
const path = require('path')

class AdminService extends Service{
    async login(obj){
        var sql = "select * from wy_user where uname = ? and upwd = ?"
        return await this.app.mysql.query(sql,[obj.uname,obj.upwd])
    }

    async getToken(data,time){
        let created = Math.floor(Date.now()/1000)
        let token = jwt.sign({
            data,
            exp:created + time
        },"my is secert")
        return token
    }
    async parseToken(token){
        var data = {}
        jwt.verify(token,"my is secert",function(err,decoded){
            if(err) throw err
            data = decoded
        })
        return data
    }
}

module.exports = AdminService
